package com.lsl.im.common;


import java.util.LinkedList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;

import android.app.Activity;
import android.app.Application;

public class App extends Application{
	
	private static App instance;
	public static SharePreferenceUtil preferences = null;
	
	private static List<Activity> mList = new LinkedList<Activity>();
	
	
	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		JPushInterface.setDebugMode(true);
        JPushInterface.init(this);		
	}
	
	public static App getContext() {
		return instance;
	}
	
	public static SharePreferenceUtil getPre() {
		if (null == preferences)
			preferences = new SharePreferenceUtil(instance);
		return preferences;
	}
	
	// add Activity
	 public static void addActivity(Activity activity) {
	  mList.add(activity);
	 }

	 public static void exit() {
	  try {
	   for (Activity activity : mList) {
	    if (activity != null)
	     activity.finish();
	   }
	  } catch (Exception e) {
	   e.printStackTrace();
	  } finally {
	   System.exit(0);
	  }
	 }

	 @Override
	 public void onLowMemory() {
	  super.onLowMemory(); 
	  System.gc();
	 }

}
